<%@ page import="java.net.CookieHandler" %><%--
  Created by IntelliJ IDEA.
  User: zhaoyang
  Date: 2020/8/5
  Time: 11:32 上午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>cookie访问页面次数</title>
</head>
<body>
<%

    //    页面访问次数

    Cookie []cookies=request.getCookies();
    int pageCount =0;
    for (int i=0;cookies!=null&&i<cookies.length;i++){
        if (cookies[i].getName().equals("page")) {
            pageCount=Integer.parseInt(cookies[i].getValue());
            break;
        }
    }
    pageCount++;
    Cookie c=new Cookie("page",String.valueOf(pageCount));
    c.setMaxAge(60*60*24*7);
    c.setPath("/");
    response.addCookie(c);
%>
<h3>您已访问了<%=pageCount%>次</h3>
</body>
</html>
